//
//  StatusCell.swift
//  SinaWeiBo
//
//  Created by tuyue on 16/3/15.
//  Copyright © 2016年 xueyang.co.ltd. All rights reserved.
//

import UIKit
import SnapKit

class StatusCell: UITableViewCell {
    //MARK: - 模型数据
    var status:Status? {
        didSet{
            //绑定模型数据
        originalView.status = status
            //如果是转发微博的话，就给转发微博赋值
            if let re = status?.retweeted_status{
            retweetedView.retweetedStatus = re
            }
            
            
        }
    }
    /**cell的初始化*/
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 添加子控件，并设置约束
    func setupUI(){
//   backgroundColor = UIColor.yellowColor()
        contentView.addSubview(originalView)
        contentView.addSubview(bottomView)
        contentView.addSubview(retweetedView)
        
      //MARK: - originalView约束
      originalView.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(contentView.snp_top)
        make.left.equalTo(contentView.snp_left)
        make.right.equalTo(contentView.snp_right)
        //测试高度
//        make.height.equalTo(100)
        
       //MARK: - reweetedView约束 
        retweetedView.snp_makeConstraints(closure: { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.left.right.equalTo(originalView)
        })
        
      //MARK: - bottomView约束
       bottomView.snp_makeConstraints(closure: { (make) -> Void in
        make.left.right.equalTo(contentView)
        make.top.equalTo(retweetedView.snp_bottom)
        make.height.equalTo(36)
        
       })
        
        //MARK: - 要想使用自动设置行高，必须对cell内的contentView进行底部约束
        contentView.snp_makeConstraints(closure: { (make) -> Void in
            make.top.left.right.equalTo(self)
            make.bottom.equalTo(bottomView.snp_bottom)
        })
        }
    }
    
    
    //MARK: - 创建子控件
    /**创建originalView视图*/
    private lazy var originalView:StatusOriginalView = StatusOriginalView()
    /**创建bottomView视图*/
    private lazy var bottomView:StatusBottomView = StatusBottomView()
    /**转发微博*/
    private lazy var retweetedView:StatusRetweetedView = StatusRetweetedView()
    
   
}
